<template>
  <div class="tool-card" @click="handleClick">
    <div class="tool-header">
      <div class="tool-icon" :style="{ backgroundColor: iconBg }">
        <el-icon :size="32" :color="iconColor">
          <component :is="icon" />
        </el-icon>
      </div>
      <div class="tool-status">
        <el-tag 
          :type="statusType" 
          size="small"
          effect="plain"
        >
          {{ statusText }}
        </el-tag>
      </div>
    </div>
    
    <div class="tool-content">
      <h3>{{ title }}</h3>
      <p>{{ description }}</p>
      
      <div class="tool-features" v-if="features.length > 0">
        <el-tag 
          v-for="feature in features" 
          :key="feature"
          size="small"
          effect="plain"
          class="feature-tag"
        >
          {{ feature }}
        </el-tag>
      </div>
    </div>
    
    <div class="tool-footer">
      <div class="usage-stats" v-if="showStats">
        <span class="usage-item">
          <el-icon><View /></el-icon>
          {{ usageCount }}
        </span>
        <span class="usage-item">
          <el-icon><Star /></el-icon>
          {{ favoriteCount }}
        </span>
      </div>
      
      <el-button 
        type="primary" 
        size="small"
        :icon="ArrowRight"
        class="tool-action"
      >
        使用工具
      </el-button>
    </div>
  </div>
</template>

<script setup lang="ts">
import { computed } from 'vue'
import { ArrowRight, View, Star } from '@element-plus/icons-vue'

interface Props {
  title: string
  description: string
  icon: any
  features?: string[]
  status?: 'available' | 'busy' | 'maintenance' | 'coming-soon'
  usageCount?: number
  favoriteCount?: number
  showStats?: boolean
  iconColor?: string
  iconBg?: string
}

const props = withDefaults(defineProps<Props>(), {
  features: () => [],
  status: 'available',
  usageCount: 0,
  favoriteCount: 0,
  showStats: true,
  iconColor: '#ffffff',
  iconBg: '#667eea'
})

const emit = defineEmits<{
  click: []
}>()

const statusType = computed(() => {
  const statusMap = {
    'available': 'success',
    'busy': 'warning',
    'maintenance': 'danger',
    'coming-soon': 'info'
  }
  return statusMap[props.status] || 'info'
})

const statusText = computed(() => {
  const statusMap = {
    'available': '可用',
    'busy': '繁忙',
    'maintenance': '维护中',
    'coming-soon': '即将推出'
  }
  return statusMap[props.status] || '未知'
})

const handleClick = () => {
  if (props.status === 'available') {
    emit('click')
  }
}
</script>

<style scoped>
.tool-card {
  background: white;
  border-radius: 16px;
  padding: 24px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
  transition: all 0.3s ease;
  cursor: pointer;
  border: 2px solid transparent;
  height: 100%;
  display: flex;
  flex-direction: column;
}

.tool-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.12);
  border-color: #667eea;
}

.tool-card:active {
  transform: translateY(-2px);
}

.tool-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 16px;
}

.tool-icon {
  width: 64px;
  height: 64px;
  border-radius: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
  transition: all 0.3s ease;
}

.tool-card:hover .tool-icon {
  transform: scale(1.05);
  box-shadow: 0 6px 16px rgba(102, 126, 234, 0.4);
}

.tool-status {
  flex-shrink: 0;
}

.tool-content {
  flex: 1;
  margin-bottom: 20px;
}

.tool-content h3 {
  font-size: 18px;
  font-weight: 600;
  color: #303133;
  margin-bottom: 8px;
  line-height: 1.4;
}

.tool-content p {
  color: #606266;
  font-size: 14px;
  line-height: 1.6;
  margin-bottom: 16px;
}

.tool-features {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.feature-tag {
  background: rgba(102, 126, 234, 0.1);
  color: #667eea;
  border: 1px solid rgba(102, 126, 234, 0.2);
  font-size: 12px;
  padding: 2px 8px;
  border-radius: 12px;
}

.tool-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: auto;
}

.usage-stats {
  display: flex;
  gap: 12px;
}

.usage-item {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  color: #909399;
}

.usage-item .el-icon {
  font-size: 14px;
}

.tool-action {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  border: none;
  border-radius: 8px;
  font-weight: 600;
  transition: all 0.3s ease;
}

.tool-action:hover {
  background: linear-gradient(135deg, #5a6fd8 0%, #6a4190 100%);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

/* 响应式设计 */
@media (max-width: 768px) {
  .tool-card {
    padding: 20px;
  }
  
  .tool-header {
    margin-bottom: 12px;
  }
  
  .tool-icon {
    width: 56px;
    height: 56px;
  }
  
  .tool-content h3 {
    font-size: 16px;
  }
  
  .tool-content p {
    font-size: 13px;
  }
  
  .tool-footer {
    flex-direction: column;
    gap: 12px;
    align-items: stretch;
  }
  
  .usage-stats {
    justify-content: center;
  }
  
  .tool-action {
    width: 100%;
  }
}
</style>